from frame_work.base_page import BasePage


class RebatePage(BasePage):
    # rebate_button = 'x=>J_Refunds'
    rebate_button = 's=>#J_Refunds'
    pay_password = 'id=>password'
    pay_confirm = 'c=>subBtn'
    # success_tips = 'c=>back'
    locator_pay_title = '一站互联--支付操作页面'
    error_tips = 'x=>//*[@id="CheckPassword"]/dd/p[2]/label[2]/font'

    def click_rebate_btn(self):
        inputs = self.find_multi_elements('t=>input')
        for input in inputs:
            value = input.get_attribute('type')
            if value == 'button':
                self.driver.execute_script("$(arguments[0]).click()", input)
                break

    # def click_rebate_btn(self):
    #
    #     # els = self.find_multi_elements('c=>report-view-btn')
    #     # el = els[1]
    #     inputs = self.find_multi_elements('t=>input')
    #     sum = 0
    #     for input in inputs:
    #         value = input.get_attribute('type')
    #         if value == 'button':
    #             sum +=1
    #             # input.click()
    #             # break
    #     print(sum)

    def input_password(self, text):
        self.type(self.pay_password, text)

    def click_confirm(self):
        self.click(self.pay_confirm)

    # def get_success_tips(self):
    #     value = self.text(self.success_tips)
    #     return value

    def switch_password_frame(self, value):
        self.switch_frame(value)

    def wait_pay_title(self, seconds):
        self.web_driver_wait_title(seconds, self.locator_pay_title)

    def get_error_tips(self):
        text = self.text(self.error_tips)
        return text
